#include "IfnVT.h"
void IfnVT::SetCoord(Coord pos)
{
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), { (short)pos.X, (short)pos.Y });
}

void IfnVT::SetForegroundColor(Color color)
{
    Color nColor = 0;
    if (color & R)nColor |= nR;
    if (color & G)nColor |= nG;
    if (color & B)nColor |= nB;
    if (color & H)nColor |= nH;
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(hOut, &csbi);
    SetConsoleTextAttribute(hOut, (csbi.wAttributes & 0xf0) | nColor);
}

void IfnVT::SetBackgroundColor(Color color)
{
    Color nColor = 0;
    if (color & R)nColor |= nR;
    if (color & G)nColor |= nG;
    if (color & B)nColor |= nB;
    if (color & H)nColor |= nH;
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(hOut, &csbi);
    SetConsoleTextAttribute(hOut, (csbi.wAttributes & 0x0f) | (nColor << 4));
}

void IfnVT::ShowCursor(bool show)
{
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO cci;
    GetConsoleCursorInfo(hOut, &cci);
    cci.bVisible = show;
    SetConsoleCursorInfo(hOut, &cci);
}

void IfnVT::FontBold(bool bold)
{
    return;
}

void IfnVT::FontUnderline(bool underline)
{
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(hOut, &csbi);
    if (underline)SetConsoleTextAttribute(hOut, csbi.wAttributes | COMMON_LVB_UNDERSCORE);
    else SetConsoleTextAttribute(hOut, csbi.wAttributes & ~COMMON_LVB_UNDERSCORE);
}

void IfnVT::SetForegroundColorEx(Color r, Color g, Color b)
{
}

void IfnVT::SetBackgroundColorEx(Color r, Color g, Color b)
{
}

void IfnVT::SetTitle(std::string str)
{
    SetConsoleTitleA(str.c_str());
}
